var e = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../utils/index"),
  s = n.helper.tabCommon;
Page({
  componentPage: ["onReachBottom", "onPullDownRefresh", "onPageScroll"],
  useStore: function (e) {
    return {
      userLocationCity: e.storage.userLocationCity,
      userLocation: e.storage.userLocation
    }
  },
  data: {
    searchValue: "",
    tabActive: 0
  },
  onLoad: function (e) {
    if (this.params = {
        type: 0,
        pattern: 0
      }, null != e && e.keywords && (this.setData({
        searchValue: e.keywords
      }), this.params.keywords = e.keywords), void 0 === (null == e ? void 0 : e.mode)) {
      var t = s.getTabMode(),
        r = s.getModeTabIndex(t);
      this.setData({
        tabActive: r
      }), this.params.mode = t
    } else if (null != e && e.mode) {
      var n = s.getModeTabIndex(null == e ? void 0 : e.mode);
      this.setData({
        tabActive: n
      }), this.params.mode = null == e ? void 0 : e.mode
    }
    var o = this.data.userLocation;
    if (o) {
      var i = o.split(","),
        u = a(i, 2),
        c = u[0],
        l = u[1];
      Object.assign(this.params, {
        longitude: c,
        latitude: l
      })
    }
    this.onRefreshList()
  },
  onCity: function () {
    $.router.push("/subpackage/common/multi-role-select/index", {
      type: "city"
    })
  },
  onClear: function () {
    this.setData({
      searchValue: ""
    }), this.params.keywords = "", this.onRefreshList()
  },
  onSearch: function (a) {
    var n = this;
    return r(e().mark((function r() {
      var s, o;
      return e().wrap((function (e) {
        for (;;) switch (e.prev = e.next) {
          case 0:
            if ("" !== (s = a.detail)) {
              e.next = 3;
              break
            }
            return e.abrupt("return", (n.params = t(t({}, n.params), {}, {
              keywords: s
            }), void n.onRefreshList()));
          case 3:
            (o = s.replace(/^(\s*)|(\s*)$/g, "")) && (n.params = t(t({}, n.params), {}, {
              keywords: o
            }), n.onRefreshList());
          case 5:
          case "end":
            return e.stop()
        }
      }), r)
    })))()
  },
  onFilterChange: function (a) {
    var n = this;
    return r(e().mark((function r() {
      var s, o, i, u, c, l, d;
      return e().wrap((function (e) {
        for (;;) switch (e.prev = e.next) {
          case 0:
            null !== (s = a.detail) && void 0 !== s && s.item && (i = a.detail.item, u = i.sort, c = i.type, l = i.mode, d = c.value, n.params = t(t({}, n.params), {}, {
              mode: l,
              type: (null == d || null === (o = d[0]) || void 0 === o ? void 0 : o.id) || 0,
              pattern: (null == u ? void 0 : u.id) || 0
            })), n.onRefreshList();
          case 2:
          case "end":
            return e.stop()
        }
      }), r)
    })))()
  },
  onRefreshList: function () {
    var t = this;
    return r(e().mark((function a() {
      var s;
      return e().wrap((function (a) {
        for (;;) switch (a.prev = a.next) {
          case 0:
            s = t.data.userLocationCity, t.params.addr = (null == s ? void 0 : s.id) || 1, $.selectComponent.call(t, "#card-list").then(function () {
              var a = r(e().mark((function r(a) {
                return e().wrap((function (e) {
                  for (;;) switch (e.prev = e.next) {
                    case 0:
                      return e.next = 2, a.setParams(t.params);
                    case 2:
                      return e.next = 4, a.setRefresh(!0);
                    case 4:
                      return e.next = 6, a.onRefresh();
                    case 6:
                      return e.next = 8, n.operateDom.moveToTop();
                    case 8:
                      return e.next = 10, a.setRefresh(!1);
                    case 10:
                    case "end":
                      return e.stop()
                  }
                }), r)
              })));
              return function (e) {
                return a.apply(this, arguments)
              }
            }());
          case 2:
          case "end":
            return a.stop()
        }
      }), a)
    })))()
  },
  onBack: function () {
    $.router.push("/pages/index/index")
  },
  onShow: function () {
    var t = this;
    return r(e().mark((function r() {
      var a;
      return e().wrap((function (e) {
        for (;;) switch (e.prev = e.next) {
          case 0:
            if (a = $.router.getParams(), e.t0 = null != a && a.isMultiRoleSelectUpdate, !e.t0) {
              e.next = 5;
              break
            }
            return e.next = 5, t.onRefreshList();
          case 5:
          case "end":
            return e.stop()
        }
      }), r)
    })))()
  }
});